/** 
* @version:1.0.1
* @Description: （对类进行功能描述）
* @author: yangdechao
* @date: datedate 2021年11月22日 下午3:23:59
*/
package cn.com.guage.flink.window;

import org.apache.flink.api.java.tuple.Tuple;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
import org.apache.flink.streaming.api.windowing.windows.GlobalWindow;
import org.apache.flink.util.Collector;

/** 
* @version:1.0.1
* @Description: （对类进行功能描述）
* @author: yangdechao
* @date: datedate 2021年11月22日 下午3:23:59
*/
public class MyProcessWindowFunction extends ProcessWindowFunction<Tuple3<String,String,Long>,Double, Tuple, GlobalWindow>{
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 7287266235096899901L;

	//iterable 输入流中的元素类型集合
    @Override
    public void process(Tuple tuple, Context context, Iterable<Tuple3<String, String, Long>> iterable, Collector<Double> out) throws Exception {
        long sum = 0;
        long count = 0;
        for (Tuple3<String,String,Long> in :iterable){
            sum+=in.f2;
            count++;
        }
        out.collect((double)(sum/count));
    }
}
